#include <stdio.h>
#include <string.h>
#include "SqList.h"

int main(int argc, char *argv[]){
	int i;
	SqList *L = NULL;

	printf("初始化线性表L\n");
	L = InitList();
	
	printf("判断线性表L是否为空\n");
	if(ListEmpty(*L)){
		printf("判断线性表L是为空,初始化%d个数据元素\n",MAXSIZE);
		for (int i = 1 ;i <=MAXSIZE; ++i)
		{
			ElemType e = i;
			ListInsert(L,i-1,e);
			printf("增加了一个数据元素,此时数据元素长度为: %d\n",ListLength(*L));
		}
	}

	
	printf("遍历元素:\n");
	for(int i=0;i<ListLength(*L);i++){
		ElemType e = -1;
		GetElem(*L,i,&e);
		printf("%5d", e);
	}
	printf("\n");

	char exis[10] = "存在";
	char *m = (char*)malloc(20*sizeof(char));
	int index = -1;
	if((index = LocateElem(*L,3))!=-1){
		strcat(m,exis);
	}
	else{
		strcat(m,"不");
		strcat(m,exis); 
	}
	printf("判断e=3元素是否存在:%s\n",m); 

	ElemType *deleteE;
	ListDelete(L,index,deleteE);
	printf("删除e=3元素后\n");
	printf("遍历元素:\n");
	for(int i=0;i<ListLength(*L);i++){
		ElemType e = -1;
		GetElem(*L,i,&e);
		printf("%5d", e);
	}
	printf("\n");

	printf("此时数据元素长度为: %d\n",ListLength(*L));


	if(ListEmpty(*L)){
		printf("线性表L为空,不清空\n");
	}else{
		printf("线性表L不为空,进行清空操作\n");
		ClearList(L);
		printf("清楚完毕,此时数据元素长度为: %d,遍历元素:\n",ListLength(*L));
		for(int i=0;i<ListLength(*L);i++){
			ElemType e = -1;
			GetElem(*L,i,&e);
			printf("%5d", e);
		}
		printf("\n");
	}

	ReleaseMemory(L); 
	printf("\n");
}